home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / scriptmanager.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  4.2 KB  |  140 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 2001 Ian Reinhart Geiser  (geiseri@kde.org)
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License as published by the Free Software Foundation; either
  7.    version 2 of the License, or (at your option) any later version.
  8.  
  9.    This library is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public License
  15.    along with this library; see the file COPYING.LIB.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.    Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef __scriptmanager_h__
  20. #define __scriptmanager_h__
  21.  
  22. #include <qvariant.h>
  23. #include <scriptclientinterface.h>
  24. #include <scriptinterface.h>
  25. #include <qdict.h>
  26. #include <qobject.h>
  27.  
  28. #include <kdelibs_export.h>
  29.  
  30. class ScriptInfo;
  31. //namespace KScriptInterface
  32. //{
  33.  
  34.     /**
  35.     *    This class is the base for all script engines.
  36.     *    @author Ian Reinhart Geiser <geiseri@kde.org>
  37.     *
  38.     **/
  39.     class KDE_EXPORT KScriptManager : public QObject, public KScriptClientInterface
  40.     {
  41.     Q_OBJECT
  42.     friend class KScriptInterface;
  43.     public:
  44.         /**
  45.         *    Create a new instance of the script engine.
  46.         */
  47.         KScriptManager(QObject *parent, const char *name);
  48.         /**
  49.         *    Destroy the current script engine.
  50.         */
  51.         virtual ~KScriptManager();
  52.         /**
  53.         *    Add a new script instance to the script engine.
  54.         *    This should be the full name and path to the desktop
  55.         *    file.
  56.         */
  57.         bool addScript( const QString &scriptDesktopFile);
  58.         /**
  59.         *    Remove a script instance from the script engine.
  60.         *    @returns the success of the operation.
  61.         */
  62.         bool removeScript( const QString &scriptName );
  63.         /**
  64.         *    Access the names of script instances from the script engine.
  65.         *    @returns a QStringList of the current scripts.
  66.         */
  67.         QStringList scripts();
  68.         /**
  69.         *    Clear all script intstances in memory
  70.         */
  71.         void clear();
  72.         /**
  73.         *    This function will allow the main application of any errors
  74.         *    that have occurred during processing of the script.
  75.         */
  76.         void error( const QString &msg ) {emit scriptError(msg);}
  77.         /**
  78.         *    This function will allow the main application of any warnings
  79.         *    that have occurred during the processing of the script.
  80.         */
  81.         void warning( const QString &msg ) {emit scriptWarning(msg);}
  82.         /**
  83.         *    This function will allow the main application of any normal
  84.         *    output that has occurred during the processing of the script.
  85.         */
  86.         void output( const QString &msg ) {emit scriptOutput(msg);}
  87.         /**
  88.         *    This function will allow feedback to any progress bars in the main
  89.         *    application as to how far along the script is.  This is very useful when
  90.         *    a script is processing files or doing some long operation that is of a
  91.         *    known duration.
  92.         */
  93.         void progress( int percent ) {emit scriptProgress(percent);}
  94.         /**
  95.         *    This function will allow feedback on completion of the script.
  96.         *    It turns the result as a KScriptInteface::Result, and a return
  97.         *    value as a QVariant
  98.         */
  99.         void done( KScriptClientInterface::Result result, const QVariant &returned )  {emit scriptDone(result, returned);}
  100.  
  101.     public slots:
  102.         /**
  103.         *    Run the selected script
  104.         */
  105.         void runScript( const QString &scriptName, QObject *context = 0, const QVariant &arg = 0 );
  106.     signals:
  107.         /**
  108.         *    Send out a signal of the error message from the current running
  109.         *    script.
  110.         */
  111.         void scriptError( const QString &msg );
  112.         /**
  113.         *    Send out a signal of the warning message from the current running
  114.         *    script.
  115.         */
  116.         void scriptWarning( const QString &msg );
  117.         /**
  118.         *    Send out a signal of the output message from the current running
  119.         *    script.
  120.         */
  121.         void scriptOutput( const QString &msg );
  122.         /**
  123.         *    Send out a signal of the progress of the current running
  124.         *    script.
  125.         */
  126.         void scriptProgress( int percent);
  127.         /**
  128.         *    Send out a signal of the exit status of the script
  129.         *
  130.         */
  131.         void scriptDone( KScriptClientInterface::Result result, const QVariant &returned);
  132.     protected:
  133.         QDict<ScriptInfo> m_scripts;
  134.         QDict<KScriptInterface> m_scriptCache;
  135.         //QStringList m_scriptNames;
  136.         QString m_currentScript;
  137.     };
  138. //};
  139. #endif
  140.